﻿/*
结点树选择 操作
添加时间：2010-10-14 
用户：李晓忠 
*/
$(document).ready(function() {

var wh = document.body.clientHeight;
    if(wh>50)
    $('#selectNodeTree').height(wh-80);
    var _parent_txtId = UrlParm.parm('setid');
    var _isSetVal = UrlParm.parm('setval');
    if (_isSetVal == undefined) _isSetVal = "1"; //1设值,0不设值

    $('#btreset').click(function() {//取消
        parent.close_dialog();
    });
    $('#btsubmit').click(function() { //确定
        if (_parent_txtId != undefined) {
            var str = '|';
            $("[name='chnode']").each(function() {
                if ($(this).attr('checked'))
                { str += $(this).val() + "|"; }

            });
            if (str == "|") str = "";
            var parentTxtId = parent.$('#' + _parent_txtId);
            if (parentTxtId != undefined && _isSetVal == "1") {
                parentTxtId.val(str);
            }
        }
        parent.close_dialog();
    });
    if (_parent_txtId != undefined) {

        $('#chall').click(function() {
            if (_isSetVal == "1") {
                if ($('#chall').attr('checked')) {
                    $("[name='chnode']").attr("checked", "true"); //全选       
                }
                else {
                    $("[name='chnode']").removeAttr("checked"); //取消全选 
                }
            }
        });

        $("[name='chnode']").each(function() {//绑定结点树上的选中状态
            var parentTxtId = parent.$('#' + _parent_txtId);
            if (parentTxtId != undefined) {
                var selectVal = parentTxtId.val();
                if (selectVal.indexOf('|' + $(this).val() + '|') >= 0) {
                    $(this).attr("checked", "true");
                }
                if (_isSetVal == "0") {
                    $(this).attr("disabled", "disabled");
                }
            }
        });
    } else {
        $("[name='chnode']").each(function() {//check box不可用
            $(this).attr("disabled", "disabled");
        });
    }
});